package com.hanbang.gycatering.classify;

import java.util.List;
import com.hanbang.gangyu.R;
import com.hanbang.gycatering.homepage.BaseFragmentActivity;
import com.hanbang.gycatering.scaleview.BrowseImageViewPager;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager.LayoutParams;
import android.support.v4.view.ViewPager.OnPageChangeListener;

/*
 * 照片浏览的界面   必须要的意图数据：imgs:照片集合  current:当前显示的第几个界面
 */
public class ImageBrowseActivity extends BaseFragmentActivity {
	private BrowseImageViewPager viewPager;
	private List<String> imagePaths;
	private MyAdapter adapter = null;
	private int current = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.browse_image);
		getWindow().setLayout(LayoutParams.MATCH_PARENT,
				LayoutParams.WRAP_CONTENT);
		imagePaths = getIntent().getStringArrayListExtra("imgs");
		current = getIntent().getIntExtra("current", current);
		viewPager = (BrowseImageViewPager) findViewById(R.id.image_viewpager);
		adapter = new MyAdapter(getSupportFragmentManager());
		viewPager.setAdapter(adapter);
		viewPager.setCurrentItem(current);
		viewPager.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {

			}
		});
	}

	private class MyAdapter extends FragmentStatePagerAdapter {

		public MyAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			String imgUrl = imagePaths.get(position);
			return new BrowseImageFragment(imgUrl);
		}

		@Override
		public int getCount() {
			return imagePaths.size();
		}

	}

}
